from langchain.chat_models import QianfanChatEndpoint
from langchain_core.prompts import PromptTemplate
from dotenv import load_dotenv

# import os
# os.environ["OPENAI_API_KEY"] = "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"

load_dotenv()
temp = """
你是一个专业的AI助手，介绍下自己，{word}
"""
llm = QianfanChatEndpoint(streaming=True)

prompt_template = PromptTemplate(input_variables=['word'], template=temp)

llm_chain = prompt_template | llm

response = llm_chain.stream({'word':'100字'})
for token in response:
    print(token.content,end="",flush=True)
print()